package com.zshan.clinic.mini.controller;

import com.zshan.clinic.admin.entity.vo.CmUserVo;
import com.zshan.clinic.admin.service.customer.CmUserService;
import com.zshan.clinic.common.response.RestResp;
import com.zshan.clinic.database.model.CmUser;
import com.zshan.clinic.mini.entity.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/cmUser")
public class CmUserController extends AbstractController {

    @Autowired
    private CmUserService cmUserService;


    /**
     * 查询用户信息
     * @return
     */
    @GetMapping("/getCmUserById")
    public RestResp<CmUserVo> getCmUserById() {
        UserInfo userInfo = getUserInfo();
        CmUserVo cmUserVo = cmUserService.getCmUserInfo(userInfo.getClinicId(),userInfo.getCmUserId());
        return RestResp.SUCCESS(cmUserVo);
    }

    /**
     * 修改用户信息
     * @param cmUser
     * @return
     */
    @PostMapping("/updateCmUser")
    public RestResp<Void> updateCmUser(@RequestBody CmUser cmUser) {
        UserInfo userInfo = getUserInfo();
        cmUser.setCmUserId(userInfo.getCmUserId());
        cmUser.setUpdateUserId(userInfo.getCmUserId());
        cmUser.setUpdateBy(userInfo.getNickName());
        cmUser.setClinicId(userInfo.getClinicId());
        cmUserService.updateCmUser(cmUser);
        return RestResp.SUCCESS();
    }

}

